package edu.gatech.cs2340.teamrocket.model.pokemon.ailments;

import edu.gatech.cs2340.teamrocket.control.WeightedRandom;
import edu.gatech.cs2340.teamrocket.model.Model;
import edu.gatech.cs2340.teamrocket.model.environment.Season;
import edu.gatech.cs2340.teamrocket.model.environment.Time;

/**
 * Factory class for creating random Ailments.
 *
 * @author Joe Tacheron
 */
public class AilmentFactory {

    /**
     * Special Ailment that represents a status of having no adverse ailment
     */
    public static final Ailment NONE = new NoAilment();

    private static Model model = Model.getInstance();

    public static Ailment random() {
        WeightedRandom<Class> random = new WeightedRandom<Class>();

        // always possible
        random.addChoice(Poison.class, 6);
        random.addChoice(BadPoison.class, 2);
        random.addChoice(Confusion.class, 4);
        random.addChoice(Paralysis.class, 4);
        random.addChoice(Pokerus.class, 1);
        // possible only at night
        if(model.getTime() == Time.NIGHT)
            random.addChoice(Sleep.class, 10);
        // only possible in winter
        if(model.getSeason() == Season.WINTER)
            random.addChoice(Freeze.class, 5);
        // only possible in summer
        if(model.getSeason() == Season.SUMMER)
            random.addChoice(Burn.class, 5);
        // only possible in !spring
        if(model.getSeason() != Season.SPRING)
            random.addChoice(Curse.class, 5);

        try{
            Class ailment = random.nextChoice();
            return (Ailment)ailment.newInstance();
        }
        catch(Exception e){
            throw new RuntimeException(e);
        }
    }
}